def is_prime(a):
    for i in range(2,int(r**(1/2)+1)):
        if a%i==0:
            return False
    return True

Num={'zero':'0','one':'1','two':'2','three':'3','four':'4','five':'5','six':'6','seven':'7','eight':'8','nine':'9',}
n=input()
l=n.split()
r=""
x1=0
x2=0
for i in l:
    if i in Num:
        r=r+Num[i]
    else:
        print("Wrong input")
        exit()
r=int(r)
if r>99 and r<1000:
    for x in range(r, r * 1000):
        if is_prime(x):
            x1=x
            break

    for z in range(r,2,-1):
        if is_prime(z):
            x2=z
            break
    if x1-r > r-x2:
        print(x2)
    if r-x2 > x1-r:
        print(x1)
else:
    print("Wrong input")

